package com.yyhh.helpcall.utils;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

public class PhoneUtils {

    /**
     * 拨打电话（直接拨打电话）
     * @param phoneNum 电话号码
     */
    public static void callPhone(Context context, String phoneNum){
        Intent intent = new Intent(Intent.ACTION_CALL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        context.startActivity(intent);
    }

    public static String formatPhone(String phone){
        if(!TextUtils.isEmpty(phone) && phone.length() >= 8){
            int start = phone.length() / 2 - 2;
            int end = start + 4;
            return phone.substring(0,start) + "****" + phone.substring(end,phone.length());
        }else{
            return phone;
        }
    }
}
